package com.xique.park.bean.transform.wechat;

import com.xique.common.core.utils.DateUtils;
import com.xique.park.bean.domain.wechat.WxMessageTemplate;
import com.xique.park.bean.dto.ParkInTemplateDTO;
import com.xique.park.bean.dto.ParkOutTemplateDTO;
import com.xique.park.bean.dto.PaymentTemplateDTO;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: xq-cloud
 * @ClassName ParkInTemplateTransform
 * @description:
 * @author: HdongSun
 * @create: 2022-09-01 19:30
 **/
@Slf4j
public class WechatSendTemplateTransform {

    public static ParkInTemplateDTO transformParkInTemplate(WxMessageTemplate template, String plate, String projectName, Date inTime) {
        ParkInTemplateDTO dto = new ParkInTemplateDTO();
        Map<String, Object> first = new HashMap<>(2);
        first.put("value", template.getFirst());
        first.put("color", template.getFirstColor());
        dto.setFirst(first);
        dto.setKeyword1(Collections.singletonMap("value", plate));
        dto.setKeyword2(Collections.singletonMap("value", projectName));
        dto.setKeyword3(Collections.singletonMap("value", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, inTime)));
        Map<String, Object> remark = new HashMap<>(2);
        remark.put("value", template.getRemark());
        remark.put("color", template.getRemarkColor());
        dto.setRemark(remark);
        return dto;
    }

    public static ParkOutTemplateDTO transformParkOutTemplate(WxMessageTemplate template, String plate, String projectName, Date inTime, Date outTime, Long totalFee) {
        ParkOutTemplateDTO dto = new ParkOutTemplateDTO();
        Map<String, Object> first = new HashMap<>(2);
        first.put("value", template.getFirst());
        first.put("color", template.getFirstColor());
        dto.setFirst(first);
        dto.setKeyword1(Collections.singletonMap("value", plate));
        dto.setKeyword2(Collections.singletonMap("value", projectName));
        dto.setKeyword3(Collections.singletonMap("value", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, inTime)));
        dto.setKeyword4(Collections.singletonMap("value", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, outTime)));
        dto.setKeyword5(Collections.singletonMap("value", String.format("%.2f",totalFee / 100.0) + "元"));
        Map<String, Object> remark = new HashMap<>(2);
        remark.put("value", template.getRemark());
        remark.put("color", template.getRemarkColor());
        dto.setRemark(remark);
        return dto;
    }

    public static PaymentTemplateDTO transformPaymentTemplate(WxMessageTemplate template, String plate, String projectName, Long stopTime, Long couponFee, Long totalFee, Date inTime) {
        PaymentTemplateDTO dto = new PaymentTemplateDTO();
        Map<String, Object> first = new HashMap<>(2);
        first.put("value", template.getFirst());
        first.put("color", template.getFirstColor());
        dto.setFirst(first);
        dto.setKeyword1(Collections.singletonMap("value", plate));
        dto.setKeyword2(Collections.singletonMap("value", String.format("%.2f",totalFee / 100.0) + "元"));
        dto.setKeyword3(Collections.singletonMap("value", String.format("%.2f",couponFee / 100.0) + "元"));
        dto.setKeyword4(Collections.singletonMap("value", DateUtils.getSecondToDate(stopTime)));
        Date outTime = new Date(inTime.getTime() + stopTime * 1000);
        log.info("入场时间：{}, {}， 出场时间：{}", inTime, inTime.getTime(), outTime);
        dto.setKeyword5(Collections.singletonMap("value", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, outTime)));
        Map<String, Object> remark = new HashMap<>(2);
        remark.put("value", template.getRemark());
        remark.put("color", template.getRemarkColor());
        dto.setRemark(remark);
        return dto;
    }
}
